Support casts in macros.#2268
Conversation
ff2b297 to
5b3d8d1
Compare
63cb97e to
56a4635
Compare
56a4635 to
4a29ecf
Compare
| /// This needs to be an std::HashMap because the cexpr API requires it. | ||
| parsed_macros: StdHashMap<Vec<u8>, cexpr::expr::EvalResult>, | ||
|
|
||
| wrapper_ids: StdHashMap<String, TypeId>, |
There was a problem hiding this comment.
Can you document this? It's not clear to me what you're trying to do here. Names can be namespaced in C++ too, which I think this wouldn't handle.
There was a problem hiding this comment.
Basically, I need a way to get the type ID from a name, e.g.
typedef unsigned long MyType;
#define MY_CONST (MyType)123So I need a way from "MyType" to c_ulong. Maybe this is possible using an existing method, but I couldn't find one.
| let kind = match &ty[..] { | ||
| ["bool"] => IntKind::Bool, | ||
| ["char"] => IntKind::Char { | ||
| is_signed: value < 0, |
There was a problem hiding this comment.
Seems very weird to do this based on the value, can you elaborate? char is signed or unsigned depending on the platform.
There was a problem hiding this comment.
Is there a way to go from "char" to the corresponding IntKind::Char with correct signedness? I guess this is a similar problem to the one with wrapper_ids above.
| let var_ty = if let Some(var_ty) = self.ty(ctx) { | ||
| var_ty | ||
| } else { | ||
| // FIXME: Parse/output macro variables as the last step when all types are known. |
There was a problem hiding this comment.
I mean, this is not possible, I believe, because the type the macro refers to by definition depends on context at the time of expansion.
There was a problem hiding this comment.
The time of expansion is after everything is parsed, so it should be the last type with the corresponding name.
There was a problem hiding this comment.
To be clear, bindgen currently is not doing the right thing for the following:
#define MY_INT 1
#define MY_INT 2In C, MY_INT expands to 2. bindgen currently generates const MY_INT: u32 = 1.
So macros should be expanded/evaluated after parsing everything, not at the time we see them.
|
☔ The latest upstream changes (presumably #2284) made this pull request unmergeable. Please resolve the merge conflicts. |
Depends on jethrogb/rust-cexpr#33.
Built-in types are already working, but I don't know how to support custom types since types are parsed after macros.
I made evaluation of
Var::tyfor custom types lazy, but some types are still missing when generating the output for macro variables.